#pragma once
#include "Common.h"
#include "TimeLine/ShotCutElement.h"

#include <QApplication>
#include <QMainWindow>
#include <QtPlayer.h>
#include <QWidget>
#include <QObject>
#include <QKeyEvent>
#include <QLabel>
#include <QTimer>
#include <QPushButton>
#include <QCloseEvent>
#include <QVBoxLayout>
#include <QSlider>
#include "Qt/VideoRenderWidget.h"

class ShotCutExportVideo
{
public:
    ShotCutExportVideo(){}
    ~ShotCutExportVideo();
    
    void Run(int& argc, char** argv, string jsonPath);

private:
    VideoElement* TimeLineVideoElement = nullptr;
};

//class ShotCutPreviewVideo : public QWidget
//{
//    Q_OBJECT

//public:
//    ShotCutPreviewVideo(QWidget *parent = 0);
//    ~ShotCutPreviewVideo();

//    void Reader(string jsonPath);
//    void Seek(int64_t SeekFrame);
//    void Play();
//    QString GetFrameString(int64 FrameNumb);

//private slots:
//    void SliderSeek(int value);
//    void UpdateSliderValue();
    
//protected:
//    void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
//    void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
    
//private:
//    QGridLayout* Layout;
//    VideoRenderWidget* Video;
//    QtPlayer* Player;
//    VideoElement* TimeLineVideoElement;
//    ShotCutTimeLine* PreviewTimeLine;
//    QLabel* LabelFrame;
//    QLabel* LabelTime;
//    QSlider* ProgressSlider;
//    QPushButton* PlayButton;
//    QTimer* Timer;
//    int64 MaxFrame;
//    int64 Fps;
//};

QT_BEGIN_NAMESPACE
namespace Ui { class ShotCutPreviewVideo; }
QT_END_NAMESPACE

class ShotCutPreviewVideo : public QMainWindow
{
    Q_OBJECT

public:
    ShotCutPreviewVideo(QWidget *parent = nullptr);
    ~ShotCutPreviewVideo();

    void Reader(string jsonPath);
    void Seek(int64_t SeekFrame);
    void Play();
    QString GetFrameString(int64 FrameNumb);

protected:
    void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;

    void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;

    void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;

    void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;

private slots:
    void UpdateSliderValue();

    void on_Button_Close_clicked();

    void on_Button_Maximize_clicked();

    void on_Button_Minimize_clicked();

    void on_Button_Play_clicked();

    void on_Button_Stop_clicked();

    void on_HorizontalSlider_Time_valueChanged(int value);

private:
private:
    Ui::ShotCutPreviewVideo *ui;
    QPoint MoveSrcPos;
    QPoint MoveRelativePos;
    VideoRenderWidget* Video;
    QtPlayer* Player;
    VideoElement* TimeLineVideoElement;
    ShotCutTimeLine* PreviewTimeLine;
    QTimer* Timer;
    int64 MaxFrame;
    int64 Fps;
};
